package com.autologistics.service;

import java.util.List;

import com.autologistics.dao.DisparterDao;
import com.autologistics.model.Disparter;
import com.autologistics.model.Ordertable;
import com.autologistics.util.PageBean;

public class DisparterServiceImpl implements DisparterService{
	DisparterDao disparterDao;
	
	public DisparterDao getDisparterDao() {
		return disparterDao;
	}

	public void setDisparterDao(DisparterDao disparterDao) {
		this.disparterDao = disparterDao;
	}

	/**
	 * @return ����ȫ��������Ա�б� or null
	 * @author cl
	 */
	public List<Disparter> listAll(){
		return disparterDao.listAll();
	}
	public List<Disparter> listByState(int state){
		return disparterDao.listByState(state);
	}
	/**
	 * ���������Ա
	 * @param dp
	 * @author cl
	 */
	public void add(Disparter dp){
		disparterDao.add(dp);
	}
	/**
	 * @param id
	 * @return ����Ա
	 * @author cl
	 */
	public Disparter getById(int id){
		return disparterDao.getById(id);
	}
	/**
	 * ��������Ա
	 * @param dp
	 * @author cl
	 */
	public void update(Disparter dp){
		disparterDao.update(dp);
	}
public PageBean queryForOnePage(final int pageSize, int page,int allRow){
		System.out.println("allRow    "+allRow);
		int totalPage = PageBean.countTotalPage(pageSize, allRow); //总页数  
		System.out.println("totalPage    "+totalPage);
		
		final int offset = PageBean.countOffset(pageSize, page); //当前页开始记录  
		System.out.println("offset    "+offset);
		final int length = pageSize; // 每页记录数    
		final int currentPage = PageBean.countCurrentPage(page); // 当前页    
		List<Disparter> list=disparterDao.queryForOnePage(offset, length);
		//把分页信息保存到Bean当中    
		PageBean pageBean  = new PageBean();    
		pageBean.setPageSize(pageSize);    
		pageBean.setCurrentPage(currentPage);    
		pageBean.setAllRow(allRow);    
		pageBean.setTotalPage(totalPage);    
		pageBean.setDisparterList(list);    
		return pageBean; 
		
		
	}
}
